package com.wutianyi.module.product.dataobject;

import java.io.Serializable;
import java.util.Date;

import com.google.common.hash.HashCode;
import com.google.common.hash.Hashing;

import com.google.common.hash.HashFunction;
import com.wutianyi.utils.Utils;

/**
 * @author hanjiewu
 * 
 */
public class ProductDO implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4493737114123587453L;
	private transient int id;
	private int companyId;
	private String name;
	private String images;
	private String description;
	private Date gmtCreate;
	private Date gmtModified;
	
	private transient int hashCode = -1;
	
	public ProductDO(int companyId, String name, String images, String description) {
		this.companyId = companyId;
		this.name = name;
		this.images = images;
		this.description = description;
		gmtCreate = new Date();
		gmtModified = new Date();
	}
	
	public ProductDO() {
		gmtCreate = new Date();
		gmtModified = new Date();
	}
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public int getCompanyId() {
		return companyId;
	}
	
	public void setCompanyId(int companyId) {
		this.companyId = companyId;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getImages() {
		return images;
	}
	
	public void setImages(String images) {
		this.images = images;
	}
	
	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public Date getGmtCreate() {
		return gmtCreate;
	}
	
	public void setGmtCreate(Date gmtCreate) {
		this.gmtCreate = gmtCreate;
	}
	
	public Date getGmtModified() {
		return gmtModified;
	}
	
	public void setGmtModified(Date gmtModified) {
		this.gmtModified = gmtModified;
	}
	
	public int hashCode() {
		if (hashCode != 0 && hashCode != -1) {
			return hashCode;
		}
		HashFunction hf = Hashing.md5();
		HashCode hc = hf.newHasher().putInt(companyId).putString(Utils.stringToString(name))
				.putString(Utils.stringToString(images))
				.putString(Utils.stringToString(description)).hash();
		hashCode = hc.asInt();
		return hashCode;
	}
}
